cmake_minimum_required(VERSION 3.5)
project(param_space)

# 1. 查找依赖包
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(std_msgs REQUIRED)

# 2. 生成消息/服务接口
rosidl_generate_interfaces(${PROJECT_NAME}
  "msg/ParamChanges.msg"
  "srv/SetParam.srv"
  "srv/GetParam.srv"
  DEPENDENCIES std_msgs
)

# 3. 包含生成的头文件路径
include_directories(
  ${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_cpp
)

# 4. 定义节点
add_executable(${PROJECT_NAME}_node src/param_space_node.cpp)

# 5. 链接依赖项
ament_target_dependencies(${PROJECT_NAME}_node
  rclcpp
  std_msgs
  rosidl_default_runtime
)
ament_export_dependencies(rosidl_default_runtime)
# 6. 关键修复：获取并链接类型支持库
rosidl_get_typesupport_target(
  typesupport_target
  ${PROJECT_NAME}
  "rosidl_typesupport_cpp"
)
target_link_libraries(${PROJECT_NAME}_node
  ${typesupport_target}
)

# 7. 安装规则
install(TARGETS ${PROJECT_NAME}_node
  DESTINATION lib/${PROJECT_NAME}
)

ament_package()
